import { _decorator, Component, ICollisionEvent, Node } from 'cc';
import { Barrier } from './Barrier';
import { Group } from './GameConstant';
import { GameManager } from './GameManager';
import { AudioManager, Audios } from '../AshFramework/Managers/AudioManager';
const { ccclass, property } = _decorator;

@ccclass('BankNote')
export class BankNote extends Barrier {

    IsCollider: boolean = false;

    protected onLoad(): void {
        super.onLoad();
        this.Collider.on(`onCollisionStay`, this.onCollisionStay, this);
    }

    onCollisionStay(event: ICollisionEvent) {
        if (this.IsCollider) return;

        if (event.otherCollider.getGroup() == Group.Weapon) {
            this.IsCollider = true;
            AudioManager.PlaySound(Audios.BankNote);
            this.node.destroy();
            GameManager.Instance.Award += GameManager.Instance.BankNoteValue;
            GameManager.Instance.showMoney(GameManager.Instance.BankNoteValue);
        }
    }
}


